import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_module/widget/web_scene.dart';

class NavigatorUtil {

  /// 左右push
  static void pushPage(BuildContext context, Widget page, {String? pageName}) {
    if (context == null || page == null) return;
    if (ObjectUtil.isEmpty(pageName)) {
      Navigator.push(
        context,
        MaterialPageRoute(
          builder: (BuildContext context) => page,
        ),
      );
    }
  }

  /// ios上下跳转
  static void present(BuildContext context, Widget page, String? pageName) {
    Navigator.push(context, CupertinoPageRoute<void>(builder: (ctx) => page,
      fullscreenDialog: pageName == pageName, // 是跳转方式类似ios上下跳转
    ));
  }

  static void pop(BuildContext context) {
    // Navigator.maybePop(context);
    Navigator.pop(context);
  }

  static void pushWeb(BuildContext context, String url, String title) {
    Navigator.push(context, MaterialPageRoute(builder: (context) {
      return WebScene(url: url, title: title);
    }));
  }

  static void showYJDialog<T>(BuildContext context, Widget child) {
    showDialog<T>(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) => child,
    );
  }
}